package com.atguigu.spzx.manager.task;

import com.atguigu.spzx.manager.mapper.OrderInfoMapper;
import com.atguigu.spzx.manager.mapper.OrderStatisticsMapper;
import com.atguigu.spzx.model.entity.order.OrderStatistics;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * title:
 * author: zgl
 * date: 2024/1/7
 * description：
 */
@Component
public class OrderStatisticsTask {

    @Autowired
    private OrderInfoMapper orderInfoMapper;

    @Autowired
    private OrderStatisticsMapper orderStatisticsMapper;


    @Scheduled(cron = "0 55 19 * * ? ")
    public void orderStatistics() {
        String createTime = new DateTime().minusDays(1).toString("yyyy-MM-dd");
        OrderStatistics orderStatistics = orderInfoMapper.selectByCreateTime(createTime);
        if(orderStatistics .getOrderDate() == null){
          orderStatistics.setOrderDate(new DateTime().minusDays(1).toDate());
          orderStatistics.setTotalNum(0);
          orderStatistics.setTotalAmount(new BigDecimal(0));
        }
        orderStatisticsMapper.insertAmmount(orderStatistics);
    }
}
